<template>
  <div class="resource">
    <el-card shadow="hover">
      <div style="margin-bottom: 10px;">
        <i class="el-icon-search" />
        <span> 筛选搜索</span>
      </div>
      <el-row :gutter="20">
        <el-form
          label-width="100px"
          :model="params"
          ref="params"
          size="small"
          class="searchForm"
        >
          <el-col :span="8">
            <el-form-item label="申请职位:" prop="type">
              <el-select
                v-model="params.type"
                placeholder="请选择申请职位"
                @change="search"
                clearable
              >
                <el-option
                  v-for="item in typeOptions"
                  :key="item.id"
                  :label="item.type"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-button
              @click="search"
              icon="el-icon-search"
              type="cyan"
              size="small"
              >搜索</el-button
            >
            <el-button
              @click="cancelData"
              icon="el-icon-circle-close"
              size="small"
              >重置</el-button
            >
          </el-col>
        </el-form>
      </el-row>
    </el-card>

    <div class="container">
      <div class="handle-box">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="small"
          :disabled="multiple"
          @click="handleDelete"
          >批量删除</el-button
        >
      </div>

      <!-- <el-card shadow="hover">
        <h4 style="margin-bottom: 10px">反馈列表</h4> -->
        <el-table
          v-loading="loading"
          :data="tableData"
          border
          class="table"
          ref="multipleTable"
          header-cell-class-name="table-header"
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            type="selection"
            width="60"
            align="center"
          ></el-table-column>
          <el-table-column type="index" label="序号" align="center" />
          <el-table-column
            label="留言人姓名"
            align="center"
            min-width="150"
            prop="name"
            :show-overflow-tooltip="true"
          >
          </el-table-column>
          <el-table-column label="申请职位" min-width="150" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.type == 1">讲师</span>
              <span v-if="scope.row.type == 2">渠道合作</span>
              <span v-if="scope.row.type == 3">认证咨询师</span>
            </template>
          </el-table-column>
          <el-table-column
            label="联系电话"
            align="center"
            prop="phone"
            min-width="150"
          >
          </el-table-column>
          <el-table-column label="申请时间" align="center" min-width="160">
            <template slot-scope="scope">{{ formatT(scope.row.createTime) }}</template>
          </el-table-column>
          <el-table-column
            label="操作"
            min-width="120"
            align="center"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                type="danger"
                size="small"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      <!-- </el-card> -->
      <div class="pagination">
        <pagination
          v-show="pageTotal > 0"
          :total="pageTotal"
          :page.sync="params.pageNum"
          :limit.sync="params.pageSize"
          @pagination="getData00"
        />
      </div>
    </div>
    <!-- 查看 -->
    <el-dialog :title="title666" :visible.sync="dialogVisible" width="600px">
      <el-form
        :model="formData"
        label-width="120px"
        size="small"
        class="form-box"
      >
        <el-row :gutter="20">
          <el-col :span="20">
            <el-form-item label="反馈人" prop="pic">
              <el-input disabled v-model="formData.pic"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="反馈内容" prop="desc">
              <el-input
                disabled
                type="textarea"
                :rows="6"
                v-model="formData.context"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" type="primary" plain size="small">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  queryUser,
  delUser,
  queryEmployment
} from "@/api/web/index";
export default {
  props: [],
  data() {
    return {
      title666: "",
      input: "",
      openFlag: true,
      loading: true,
      //数据
      tableData: [],
      typeOptions: [

      ],
      params: {
        pageNum: 1,
        pageSize: 10,
        type: undefined,
      },
      pageTotal: 0,
      dialogVisible: false, // 是否展示编辑页面
      // 删除砖用
      multiple: true,
      ids: [],
      // 新增/编辑数据
      formData: {}
    };
  },
  computed: {},
  created() {
    this.getTeach()
    this.getData00();
  },
  mounted() {},
  watch: {},
  methods: {
    getTeach() {
      queryEmployment().then(res => {
        if(res.code == 200){
          this.typeOptions = res.rows
        }
      })
    },
    // 重置搜索框
    cancelData() {
      this.resetForm("params");
      this.getData00();
    },
    handleEdit(row) {
      this.formData = row;
      this.dialogVisible = true;
      this.title666 = "查看";
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id || this.ids;
      this.$confirm("是否确认删除?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delUser(id);
        })
        .then(() => {
          this.getData00();
          this.msgSuccess("删除成功");
        })
        .catch(function () {});
    },
    //获取数据
    getData00() {
      var _this = this;
      let data = this.params;
      queryUser(data)
        .then((res) => {
          if (res.code == 200) {
            this.tableData = res.rows;
            this.pageTotal = res.total;
            this.loading = false;
          }
        })
        .catch(() => {
          console.log("error submit!!");
          return false;
        });
    },
    // 触发搜索按钮
    search() {
      this.$set(this.params, "pageNum", 1);
      this.getData00();
    },
    // 分页导航
    handlePageChange(val) {
      this.$set(this.params, "pageNum", val);
      this.getData00();
    },
  },
};
</script>

<style scoped>
.resource {
  padding: 30px;
}
.container {
  margin-top: 20px;
}
.handle-box {
  margin-bottom: 10px;
}
.table {
  width: 100%;
  font-size: 14px;
}
.red {
  color: #ff0000;
}
.yellow {
  color: #f57506;
}
.green {
  color: green;
  cursor: pointer;
}
.blue {
  color: #409eff;
  cursor: pointer;
  text-decoration: underline;
}
.mr10 {
  margin-right: 10px;
}

.searchForm .el-form-item--mini.el-form-item,
.searchForm .el-form-item--small.el-form-item {
  margin-bottom: 1px;
}
.study_pic {
  display: block;
  width: 60px;
  height: 60px;
  margin: auto;
  border-radius: 50%;
}
</style>
